package tech.aistar.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tech.aistar.mapper.ProductMapper;
import tech.aistar.pojo.Product;

import java.util.List;

/**
 * 业务ProductService接口的实现类
 */
@Service // 将业务逻辑层的组件交给spring容器来管理
public class ProductServiceImpl implements ProductService{
    //service层调用Mapper层,需要声明mapper
    @Autowired
    private ProductMapper productMapper;

    @Override
    public List<Product> listAll() {
        //TODO... 未来开发中此处可能需要写大量的业务代码
        return productMapper.findAll();
    }

    @Override
    public PageInfo<Product> page(Integer pageNum, Integer pageSize) {
        //设置分页的属性
        PageHelper.startPage(pageNum,pageSize);
        //调用mapper查询所有的产品的方法
        List<Product> list = productMapper.findAll();
        //拦截select语句,后面拼接分页的语句limit
        PageInfo<Product> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
